package myJs

import myJs.myPkg.LayerOptions
import myJs.myPkg.jquery.$
import scalatags.Text.all._

import scala.scalajs.js

/**
 * Created by yz on 28/8/2020
 */
object Tool {

  val zhRunning = "正在运行"
  val myElement = div(id := "content")(
    span(id := "info")(zhRunning),
    " ",
    img(src := "/assets/images/running2.gif", width := 30, height := 20, cls := "runningImage")
  ).render
  val zhInfo = "信息"
  val layerOptions = LayerOptions.title(zhInfo).closeBtn(0).skin("layui-layer-molv").btn(js.Array())
  val confirmButtonClass = "btn-danger"
  val cancelButtonClass = "green"


  def fillByNames(rs: js.Dictionary[String], formId: String) = {
    val names = $(s"#${formId} .fillByName").mapElems { y =>
      $(y).attr("name").toString
    }.toArray
    names.foreach { name =>
      fillByName(rs, name, formId)
    }
  }

  def fillByName(rs: js.Dictionary[String], name: String) = {
    val valOp = rs.get(name)
    valOp.foreach { value =>
      $(s":input[name='${name}']").`val`(value)
    }
  }

  def fillByName(rs: js.Dictionary[String], name: String, formId: String) = {
    val value = rs(name)
    $(s"#${formId} :input[name='${name}']").`val`(value)
  }

  def getInputByName(name: String) = {
    $(s":input[name='${name}']")
  }

}
